home *** CD-ROM | disk | FTP | other *** search
/ SGI Developer Toolbox 6.1 / SGI Developer Toolbox 6.1 - Disc 4.iso / public / SciAn / src / ScianPictures.h < prev    next >
C/C++ Source or Header  |  1994-08-01  |  13KB  |  420 lines

  1. /*ScianPictures.h
  2.   Eric Pepke
  3.   External stuff and data structures for ScianPictures.c
  4. */
  5.  
  6. #define CARDBASIS    1    /*Basis for cardinal spline*/
  7.  
  8. #define SOLIDLINE    0    /*Solid line*/
  9. #define DASHEDLINE    1    /*Line style for dashed line*/
  10. #define DOTTEDLINE    2    /*Line style for dotted line*/
  11.  
  12. /*Values for picture item type.  Must go from 0 up by ones*/
  13. #define POLYGON        0    /*Type for a polygon*/
  14. #define FRUSTUM        1    /*Conical frustum*/
  15. #define SPHERE        2    /*Sphere*/
  16. #define RECTMESH    3    /*Rectangular mesh*/
  17. #define PLANARPOLYGON    4    /*Planar polygon*/
  18. #define POLYGONS    5    /*A bunch of polygons*/
  19. #define POLYLINE    6    /*A polyline*/
  20. #define POLYPOINT    7    /*A polypoint*/
  21. #define POLYTRI        8    /*Triangular strip*/
  22. #define NPICITEMTYPES    9    /*Numcber of pic types*/
  23.  
  24. /*Vertex flags*/
  25. #define VF_DEFORMED    1    /*Set iff vertex currently deformed*/
  26. #define VF_COLORED    2    /*Set iff vertex currently colored*/
  27. #define VF_SAMEPLACE    4    /*Set iff vertex should be considered in the
  28.                   same place as last for color and deform*/
  29. #define VF_FIRSTCANON    8    /*Set iff vertex is a first canonical vertex*/
  30. #define VF_NEXTCANON    16    /*Set iff vertex is a next to last canonical vertex*/
  31. #define VF_DONTDRAW    32    /*Don't draw as a point*/
  32.  
  33. extern Bool orderReversed;    /*True iff drawing order is reversed*/
  34. extern Bool overrideColor;    /*True iff override color commands*/
  35.  
  36. /*Vertex tuple*/
  37. typedef struct vertx
  38.     {
  39.     float normal[3];    /*Normal at that vertex*/
  40.     float position[3];    /*Position of that vertex*/
  41.     short colorIndex;    /*Color within color table*/
  42.     short flags;        /*Flags for vertex*/
  43.     struct vertx *next;    /*Pointer to next vertex in list*/
  44.     } Vertex, *VertexPtr;
  45.  
  46. /*Item in a picture*/
  47. typedef struct picitem
  48.     {
  49.     struct picitem *next;    /*Next item in list*/
  50.     short type;        /*Type of item.  Based on this, it's really
  51.                   interpreted as something else*/
  52.     short proximity;    /*Extra proximity*/
  53.     short flags;
  54.     } PicItem, *PicItemPtr;
  55.  
  56. /*Values for picture item flags*/
  57. #define PF_CANONVERTICES    1    /*Vertices are in canonical order*/
  58.  
  59. /*Don't change the values of these defines!*/
  60. /*Values for color shading*/
  61. #define NOCOLOR        0
  62. #define MONOCOLOR    1
  63. #define SMOOTHCOLOR    2
  64.  
  65. /*Values for light shading*/
  66. #define NOLIGHT        0
  67. #define MONOLIGHT    1
  68. #define SMOOTHLIGHT    2
  69. #define DEPTHCUELIGHT    3
  70.  
  71. /*Values for current color mode*/
  72. #define CMODECMAP    0
  73. #define CMODERGB    1
  74.  
  75. /*Polygon or poly line or poly point*/
  76. typedef struct
  77.     {
  78.     PicItem item;        /*The item part*/
  79.     int lineWidth;        /*Line width*/
  80.     VertexPtr centerVertex;    /*The vertex at the center*/
  81.     long nVertices;        /*Number of vertices*/
  82.     VertexPtr vertices[1];  /*The vertices*/
  83.     } Polygon, Polyline, Polypoint, Polytri, *PolyPtr;
  84.  
  85. /*A bunch of polygons, all with the same colorShading and lightShading*/
  86. typedef struct
  87.     {
  88.     PicItem item;        /*The item part*/
  89.     Bool enclosed;        /*True iff totally enclosed*/
  90.     struct pic *picture;    /*The picture it belongs to, for backing up*/
  91.     PolyPtr polygons;    /*The polygons*/
  92.     PolyPtr lastItem;
  93.     } Polygons, *PolysPtr;
  94.  
  95. /*Conical frustum*/
  96. typedef struct
  97.     {
  98.     PicItem item;        /*The item part*/
  99.     float end1[3];        /*First endpoint*/
  100.     float rad1;        /*Radius at first endpoint*/
  101.     float end2[3];        /*Second endpoint*/
  102.     float rad2;        /*Radius at second endpoint*/
  103.     int colorIndex;        /*Color index*/
  104.     } Frustum, *FrustumPtr;
  105.  
  106. /*Sphere*/
  107. typedef struct
  108.     {
  109.     PicItem item;        /*The item part*/
  110.     VertexPtr centerVertex;    /*The center of the sphere*/
  111.     float radius;        /*The radus of the sphere*/
  112.     } Sphere, *SpherePtr;
  113.  
  114. /*Rectangular mesh*/
  115. typedef struct
  116.     {
  117.     PicItem item;        /*The item part*/
  118.     Bool inCenter;        /*Nodes are in center rather than around*/
  119.     long xDim;        /*Y dimension*/
  120.     long yDim;        /*X dimension*/
  121.     VertexPtr vertices[1];    /*The vertices*/
  122.     } RectMesh, *RectMeshPtr;
  123.  
  124. /*Picture*/
  125. typedef struct pic
  126.     {
  127.     Thing thing;
  128. #ifdef MAKEOBJ
  129.     Object picObj;        /*The picture object for Silicon Graphics*/
  130. #endif
  131.     VertexPtr vertices;    /*The vertices used in the picture*/
  132.     VertexPtr lastVertex;    /*The last vertex for adding onto the list*/
  133.     PicItemPtr items;    /*The list of actual items*/
  134.     PicItemPtr lastItem;
  135.     } Picture, *PicPtr;
  136.  
  137. #define RECTMESHVERTEX(rectMesh, i, j) ((j) * 2 + (i) * (2 * (rectMesh) -> yDim - 1))
  138. #define RECTMESHCENTER(rectMesh, i, j) ((j) * 2 + 1 + (i) * (2 * (rectMesh) -> yDim - 1))
  139.  
  140. /*Deforms vertex v*/
  141.  
  142. #define DEFORMVERTEX(v) if (globalDeformObject)                \
  143.     {                                \
  144.         real position[3];                    \
  145.         real sample;                        \
  146.                                     \
  147.         position[0] = (v) -> position[0];                \
  148.         position[1] = (v) -> position[1];                \
  149.         position[2] = (v) -> position[2];                \
  150.                                     \
  151.         sample = SampleSpatScalar(DEFORMFIELD, DEFORMFORM,    \
  152.              3, position, true);                \
  153.         if (sample != missingData)                \
  154.         {                            \
  155.         (v) -> position[0] =             \
  156.             ((v) -> position[0] + (v) -> normal[0] *     \
  157.             (sample * globalFactor + globalOffset)) ;    \
  158.         (v) -> position[1] =             \
  159.             ((v) -> position[1] + (v) -> normal[1] *     \
  160.             (sample * globalFactor + globalOffset));    \
  161.         (v) -> position[2] =             \
  162.             ((v) -> position[2] + (v) -> normal[2] *     \
  163.             (sample * globalFactor + globalOffset));    \
  164.         }                            \
  165.     }                                \
  166.     else                                \
  167.     {                                \
  168.         (v) -> position[0] =             \
  169.             ((v) -> position[0] + (v) -> normal[0] *         \
  170.             (globalFixed * globalFactor + globalOffset));    \
  171.         (v) -> position[1] =             \
  172.             ((v) -> position[1] + (v) -> normal[1] *         \
  173.             (globalFixed * globalFactor + globalOffset));    \
  174.         (v) -> position[2] =             \
  175.             ((v) -> position[2] + (v) -> normal[2] *         \
  176.             (globalFixed * globalFactor + globalOffset));    \
  177.     }                                \
  178.  
  179. /*Vertex drawing macros.  Hate to do it like this, but...
  180.  
  181.   The name is by this convention:
  182.  
  183.   PRNS(vertexPointer, nVertices)
  184.   ^^^^
  185.   ||||
  186.   |||+- Color shading, either (N)one, (M)ono, or (S)mooth
  187.   ||+-- Light shading, either (N)one, (M)ono, (S)mooth, or (D)epthcue
  188.   |+--- Color mode, either (R)GB or (C)MAP
  189.   +---- This is always a P, for prepare to draw vertices
  190.  
  191.   VRNS(vertex)
  192.   ^^^^
  193.   ||||
  194.   |||+- Color shading, either (N)one, (M)ono, or (S)mooth
  195.   ||+-- Light shading, either (N)one, (M)ono, (S)mooth, or (D)epthcue
  196.   |+--- Color mode, either (R)GB or (C)MAP
  197.   +---- This is always a V, for draw vertex
  198.  
  199.   They all have to be separate for efficiency's sake
  200. */
  201.  
  202. #define EXPMINMAX(t, min, max) if ((t) > (max)) (max) = (t); if ((t) < (min)) (min) = (t);
  203.  
  204. /*Color map macros*/
  205. #define PCNN(vP, nV)
  206. #define VCNN(v) v3f((*v) -> position);
  207.  
  208. #define PCNM(vP, nV) {int k; long cMin, cMax; VertexPtr (*v); v=vP; cMin=cMax=(*v) -> colorIndex; for(k=1;k<nV;++k) {++v; EXPMINMAX((*v)->colorIndex, cMin, cMax);} color(curBeg + (cMin + cMax) / 2);}
  209. #define PCNMSKIP(vP, nV) {int k; long cMin, cMax; VertexPtr (*v); v=vP; cMin=cMax=(*v) -> colorIndex; for(k=1;k<nV;++k) {v+=nX; EXPMINMAX((*v)->colorIndex, cMin, cMax);} color(curBeg + (cMin + cMax) / 2);}
  210. #define VCNM(v) v3f((*v) -> position);
  211.  
  212. #define PCNS(vP, nV)
  213. #define VCNS(v) color(curBeg + (*v) -> colorIndex); v3f((*v) -> position);
  214.  
  215.  
  216. #define PCMN(vP, nV)
  217. #define VCMN(v) color((int) (curBeg + 2 + ((*v) -> normal[0] * 0.5 + 0.5) * (curNColors - 5))); v3f((*v) -> position);
  218.  
  219. #define PCMM PCNM
  220. #define VCMM VCNM
  221.  
  222. #define PCMS PCNS
  223. #define VCMS VCNS
  224.  
  225.  
  226. #define PCSN PCMN
  227. #define VCSN VCMN
  228.  
  229. #define PCSM PCMM
  230. #define VCSM VCMM
  231.  
  232. #define PCSS PCMS
  233. #define VCSS VCMS
  234.  
  235.  
  236. #define PCDN PCNN
  237. #define VCDN VCNN
  238.  
  239. #define PCDM PCNM
  240. #define PCDMSKIP PCNMSKIP
  241. #define VCDM VCNM
  242.  
  243. #define PCDS PCNS
  244. #define VCDS VCNS
  245.  
  246. #define C3S(x)    if (overrideColor == false) c3s(x)
  247. #define N3F(x)  if (overrideColor == false) n3f(x)
  248.  
  249. /*RGB macros*/
  250. #define PRNN(vP, nV)
  251. #define VRNN(v) v3f((*v) -> position);
  252.  
  253. #define PRNM(vP, nV) {int k; long cMin, cMax; VertexPtr (*v); v = vP; cMin = cMax = (*v) -> colorIndex; for(k=1;k<nV;++k) {++v; EXPMINMAX((*v)->colorIndex, cMin, cMax);} C3S(curColors[(cMin + cMax) / 2]);}
  254. #define PRNMSKIP(vP, nV) {int k; long cMin, cMax; VertexPtr (*v); v = vP; cMin = cMax = (*v) -> colorIndex; for(k=1;k<nV;++k) {v+=nX; EXPMINMAX((*v)->colorIndex, cMin, cMax);} C3S(curColors[(cMin + cMax) / 2]);}
  255. #define VRNM(v) v3f((*v) -> position);
  256.  
  257. #define PRNS(vP, nV)
  258. #define VRNS(v) C3S(curColors[(*v) -> colorIndex]); v3f((*v) -> position);
  259.  
  260.  
  261. #define PRMN PRNN
  262. #define VRMN(v) N3F((*v) -> normal); v3f((*v) -> position);
  263.  
  264. #define PRMM PRNM
  265. #define VRMM(v) N3F((*v) -> normal); v3f((*v) -> position);
  266.  
  267. #define PRMS PRMM
  268. #define VRMS(v) C3S(curColors[(*v) -> colorIndex]); N3F((*v) -> normal); v3f((*v) -> position);
  269.  
  270.  
  271. #define PRSN PRMN
  272. #define VRSN VRMN
  273.  
  274. #define PRSM PRMM
  275. #define VRSM VRMM
  276.  
  277. #define PRSS PRMM
  278. #define VRSS VRMS
  279.  
  280. /*Depth cue*/
  281. #define PRDN(vP, nV) 
  282. #define VRDN(v)  v3f((*v) -> position);
  283.  
  284. #define PRDM(vP, nV)  {int k; long cMin, cMax; VertexPtr (*v); v = vP; cMin = cMax = (*v) -> colorIndex; for(k=1;k<nV;++k) {++v; EXPMINMAX((*v)->colorIndex, cMin, cMax);}\
  285.     k = (cMin + cMax) / 2;    \
  286.     lRGBrange(0,        \
  287.           0,        \
  288.           0,        \
  289.           curColors[k][0],        \
  290.           curColors[k][1],        \
  291.           curColors[k][2], curZMin, curZMax);}
  292. #define PRDMSKIP(vP, nV)  {int k; long cMin, cMax; VertexPtr (*v); v = vP; cMin = cMax = (*v) -> colorIndex; for(k=1;k<nV;++k) {v+=nX; EXPMINMAX((*v)->colorIndex, cMin, cMax);}\
  293.     k = (cMin + cMax) / 2;    \
  294.     lRGBrange(0,        \
  295.           0,        \
  296.           0,        \
  297.           curColors[k][0],        \
  298.           curColors[k][1],        \
  299.           curColors[k][2], curZMin, curZMax);}
  300. #define VRDM(v) v3f((*v) -> position);
  301.  
  302. #define PRDS(vP, nV)
  303. #define VRDS(v)    {int k; k = (*v) -> colorIndex;        \
  304.     lRGBrange(0,        \
  305.           0,        \
  306.           0,        \
  307.           curColors[k][0],        \
  308.           curColors[k][1],        \
  309.           curColors[k][2], curZMin, curZMax);        \
  310.           v3f((*v) -> position);}
  311.  
  312. /*Versions for rect mesh with center nodes*/
  313. #define MCRPCNM(vP) color(curBeg + (*(vP)) -> colorIndex);
  314. #define MCRPRNM(vP) C3S(curColors[(*(vP)) -> colorIndex]);
  315.  
  316. #ifdef PROTO
  317. ObjPtr NewPicture(void);
  318. PolyPtr AppendPolyToPicture(ObjPtr, long, Vertex[]);
  319. PolyPtr AppendPolylineToPicture(ObjPtr, int, int, long, Vertex[]);
  320. PolyPtr AppendSPolylineToPicture(ObjPtr, int, int, long, VertexPtr[]);
  321. PolyPtr AppendSPolypointToPicture(ObjPtr, int, long, VertexPtr[]);
  322. PolyPtr AppendPolyToPolys(PolysPtr, long, Vertex[]);
  323. PolyPtr AppendSPolyToPolys(PolysPtr, long, VertexPtr[]);
  324. PolyPtr TesselateSPolyToPicture(ObjPtr, long, VertexPtr[]);
  325. FrustumPtr AppendFrustumToPicture(ObjPtr, float end1[3], float, float end2[3], float, int);
  326. PolysPtr AppendPolysToPicture(ObjPtr);
  327. SpherePtr AppendSphereToPicture(ObjPtr, float center[3], float, int);
  328. RectMeshPtr AppendRectMeshToPicture(ObjPtr, long, long, Bool);
  329. void DrawPicture(ObjPtr, Bool, int, int, ObjPtr);
  330. void PrepareToDraw(Bool, int, int, ObjPtr);
  331. void DoneDrawing();
  332. void GetPictureBounds(ObjPtr, real bounds[6]);
  333. void InitPictures(void);
  334. void KillPictures(void);
  335. void ColorPictureByObject(ObjPtr, ObjPtr, Bool);
  336. void DeformPictureByObject(ObjPtr);
  337. void CalcPictureNormals(ObjPtr);
  338. void UnColorPicture(ObjPtr);
  339. VertexPtr RectMeshVertex(RectMeshPtr rectMesh, long i, long j);
  340. VertexPtr RectMeshCenter(RectMeshPtr rectMesh, long i, long j);
  341. void InterpRectCenters(RectMeshPtr);
  342. void InterpRectVertices(RectMeshPtr);
  343. void CalcRectNormals(RectMeshPtr);
  344. ObjPtr ConvertPicture(ObjPtr, ObjPtr);
  345. ObjPtr ConvertOntoPicture(ObjPtr, ObjPtr, ObjPtr);
  346. void ColorItemsByObject(PicItemPtr curItem, ObjPtr colorObj, Bool);
  347. void DeformItemsByObject(PicItemPtr curItem);
  348. void ColorItemByObject(PicItemPtr curItem, ObjPtr colorObj, Bool);
  349. void DeformItemByObject(PicItemPtr curItem);
  350. void ColorItemsWithIndex(PicItemPtr curItem, int);
  351. void ColorItemWithIndex(PicItemPtr curItem, int);
  352. void ColorPictureByPicture(ObjPtr, ObjPtr, ObjPtr);
  353. PicItemPtr ColorItemsByItems(PicItemPtr destItem, ObjPtr owner, PicItemPtr curItem);
  354. VertexPtr NewVertex(ObjPtr, int);
  355. VertexPtr InsertVertex(ObjPtr, VertexPtr);
  356. void FreeVertex(VertexPtr);
  357. void ConvertFrustumOntoPicture(ObjPtr, float end1[3], float, float end2[3], float, int, Bool);
  358. PolysPtr ConvertSphereOntoPicture(ObjPtr, VertexPtr, real, int, int);
  359. void ZeroPictureTime(void);
  360. long GetPictureTime(void);
  361. ObjPtr NewOpenGraphObj(void);
  362. void OpenGraphObj(ObjPtr);
  363. void DrawGraphObj(ObjPtr);
  364. void CloseGraphObj(ObjPtr);
  365. void OverrideColor(Bool);
  366. void BeginMask(Bool, Bool, Bool, Bool);
  367. void EndMask(void);
  368. #else
  369. Bool AppendPolyToPicture();
  370. PolyPtr AppendPolylineToPicture(ObjPtr, int, int, int, Vertex[]);
  371. PolyPtr AppendSPolypointToPicture(ObjPtr, int, int, int, Vertex[]);
  372. Bool AppendPolyToPolys();
  373. Bool AppendFrustumToPicture();
  374. PolyPtr AppendSPolyToPolys(PolysPtr, int, VertexPtr[]);
  375. PolysPtr AppendPolysToPicture();
  376. void ConvertFrustumOntoPicture();
  377. Bool AppendSphereToPicture();
  378. ObjPtr NewPicture();
  379. void DrawPicture();
  380. void PrepareToDraw();
  381. void DoneDrawing();
  382. void GetPictureBounds();
  383. void InitPictures();
  384. void KillPictures();
  385. void ColorPictureByObject();
  386. void DeformPictureByObject();
  387. void CalcPictureNormals();
  388. void UnColorPicture();
  389. VertexPtr RectMeshVertex();
  390. VertexPtr RectMeshCenter();
  391. void InterpRectCenters();
  392. void InterpRectVertices();
  393. void CalcRectNormals();
  394. ObjPtr ConvertPicture();
  395. ObjPtr ConvertOntoPicture();
  396. PolysPtr SphereToPolys();
  397. void ColorItemsByObject();
  398. void DeformItemsByObject();
  399. void ColorItemByObject();
  400. void DeformItemByObject();
  401. void ColorItemsWithIndex();
  402. void ColorItemWithIndex();
  403. void ColorPictureByPicture();
  404. PicItemPtr ColorItemsByItems();
  405. VertexPtr NewVertex();
  406. VertexPtr InsertVertex();
  407. void FreeVertex();
  408. void ConvertFrustumOntoPicture();
  409. PolysPtr ConvertSphereOntoPicture();
  410. void ZeroPictureTime();
  411. long GetPictureTime();
  412. ObjPtr NewOpenGraphObj();
  413. void OpenGraphObj();
  414. void DrawGraphObj();
  415. void CloseGraphObj();
  416. void OverrideColor();
  417. void BeginMask();
  418. void EndMask();
  419. #endif
  420.